/*
 * @Author: 康家赫 13349195+kangjiahe666@user.noreply.gitee.com
 * @Date: 2024-04-26 11:35:50
 * @LastEditors: 康家赫 13349195+kangjiahe666@user.noreply.gitee.com
 * @LastEditTime: 2024-04-26 16:14:16
 * @FilePath: \MDK-ARMd:\Desktop\mcu_practice\mcu_experience1\kjh_usingcode\rocker.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "adc.h"
#include "rocker.h"
#include <stdint.h>
#include "oled.h"
int rocker_x_value;
int rocker_y_value;

void rocker_init(void)
{   
    HAL_ADCEx_Calibration_Start(&hadc1);
    HAL_ADC_Start(&hadc1);
}

uint16_t ADC_Read(uint32_t Channel)
{
  ADC_ChannelConfTypeDef sConfig = {0};
  sConfig.Channel = Channel; /* ?? */
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_55CYCLES_5; /* ???? */
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  HAL_ADC_Start(&hadc1);
  HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
  return (uint16_t)HAL_ADC_GetValue(&hadc1);
}
void rocker_show_value(int ADC_Y_Value,int ADC_X_Value)
{
    ADC_Y_Value = ADC_Read(ADC_CHANNEL_0);
    ADC_X_Value = ADC_Read(ADC_CHANNEL_1);
	  OLED_ShowNum(0, 50,  ADC_Y_Value, 4, 16);
    OLED_ShowNum(90, 50, ADC_X_Value, 4, 16);
    OLED_Refresh();

}
